package me.m1key.springtx.beans;

import me.m1key.springtx.dao.DogsDao;
import me.m1key.springtx.entities.Dog;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class DogsBean {

	private DogsDao dogsDao;

	/**
	 * Returns true if there is at least one dog in the database.
	 * 
	 * @return true if there is a dog in the database
	 */
	public boolean containsDogs() {
		return dogsDao.retrieveNumberOfDogs() > 0;
	}

	/**
	 * Persists the dog to the database.
	 * 
	 * @param dog
	 *            dog to persist
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public void persistDog(Dog dog) {
		dogsDao.persistDog(dog);
	}

	/**
	 * Updates the dog.
	 * 
	 * @param dog
	 *            dog to persist
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public void updateDog(Dog dog) {
		dogsDao.updateDog(dog);
	}

	protected DogsDao getDogsDao() {
		return dogsDao;
	}

	public void setDogsDao(DogsDao dogsDao) {
		this.dogsDao = dogsDao;
	}

}
